<?php
class File extends Doctrine_Record {
		
	public function setTableDefinition() {
    $this->hasColumn('name', 'string', 255,
    	array(
				'notnull' => true,
    		'comment' => 'nombre del archivo'
      )
    );
    
    $this->hasColumn('document_id', 'integer', 4,
    	array(
    		'notnull' => true,
    		'comment' => 'id del documento al que pertenece el archivo.'
      )
    );
    
	}
	
	public function setUp() {
		$this->hasOne('Document as document', 
			array(
				'local' => 'document_id',
				'foreign' => 'id',
				'onDelete' => 'CASCADE'
			)
		);
	}

	static public function getFilenameByDocument_Id($document_id) {
	  $query = Doctrine_Query::create()
	    ->select('name')
	    ->from('File')
	    ->where('document_id = ?', $document_id);
	    
	  $files = $query->execute();
	  return $files[0]->name;
	}
}